import time
from selenium.webdriver.support import expected_conditions as EC
from page_object.queuedatareport import QueueDatareport
from tools.base_page import BasePage


class QueueData(BasePage):

    _base_url = 'http://172.16.10.21/mrpv2/#/dataReportList'

    def open_queue_page(self):
        time.sleep(2)
        self.driver.get(self._base_url)
        time.sleep(2)
        return self

    def crux_search(self,search_text):
        '''
        队列数据报告关键字搜索
        :param search_text:
        :return:
        '''

        self.open_yaml_element('../data/queue_data_report.yaml','search_input',content=search_text)
        self.elementclickintercepted(self.only_read_yaml('../data/queue_data_report.yaml','search_click'))
        time.sleep(2)
        return self

    def verify_search_res(self):
        '''
        验证搜索结果
        :return:
        '''
        team_name_locator = self.only_read_yaml('../data/queue_data_report.yaml','team_name')
        team_name_text = self.find(team_name_locator).text
        return team_name_text


    def verify_not_search_res(self):
        '''
        验证无搜索结果
        :return:
        '''
        total_name = self.only_read_yaml('../data/queue_data_report.yaml','total_name')
        total_name_text = self.find(total_name).text
        return total_name_text


    def cat_report(self):
        '''
        队列数据报告查看报告
        :return:
        '''
        report_status = self.only_read_yaml('../data/queue_data_report.yaml','report_status_finish')  # report_status locator
        report_status_eles = self.elements(report_status)  # report_status_eles  is list
        operate_locator = self.only_read_yaml('../data/queue_data_report.yaml','cat_report')
        time.sleep(3)
        eles = self.elements(operate_locator)
        return self.verify_locator_is_not_click(eles)


    def report_cat_page(self):
        '''
        翻页点击
        :return:
        '''
        self.open_yaml_element('../data/queue_data_report.yaml','click_page')
        click_num_page = self.only_read_yaml('../data/queue_data_report.yaml','click_page')


        for num in range(5,8):
            list_num_page = list(click_num_page)
            list_num_page[1] = '.mini>li:nth-child({})'.format(num)
            self.find(list_num_page).click()
            time.sleep(2)
        return True

    def verify_locator_is_not_click(self,eles):
        # 判断查看报告按钮是否可点击 ，点击ele[0]后，如果ele[0]是可点击的就会跳转url。判断部分路径是否存在于获取到的url。
        # eles: find_elements的对象

        for num in range(10):
            eles[num].click()
            time.sleep(2)
            get_present_url = self.driver.current_url  # 当前url
            time.sleep(2)
            url_part_path = '/mrpv2/#/variableReport?name'  # 点击查看报告后跳转的新url的部分路径
            try:
                if url_part_path in get_present_url:
                    return True
            except:
                self.verify_locator_is_not_click(eles)








